package mwa.cs.dao;

import java.util.List;
import java.util.Map;

import mwa.cs.database.Database;

/**
 * A class used for managing SM_LISTOFVALUE
 */
public class SMListOfValueDAO {

    /** a database of this SM_LISTOFVALUE */
    private Database db;

    /**
     * Instantiate a new object of this class
     * @param database a database
     */
    public SMListOfValueDAO(Database db) {
        this.db = db;
    }

    /**
     * a method for searching SM_LISTOFVALUE in database by input Type of value
     * @return code, name which in the type of value
     */
    public List<Map<String, Object>> findLOVByType(String paLovType) {
        String vaSql = "SELECT lov_code, lov_name FROM sm_listofvalue WHERE lov_type=? ORDER BY lov_code ASC";
        List<Map<String, Object>> result = db.queryList(vaSql, paLovType);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    public String findStatusByCodeAndType(String paLovCode, String paLovType) {
        String vaSql = "SELECT lov_name FROM sm_listofvalue WHERE lov_code = ? and lov_type = ?";
        Map<String, Object> result = db.querySingle(vaSql, paLovCode, paLovType);
        if (result != null) {
            return (String) result.get("LOV_NAME");
        } else {
            return null;
        }
    }
    
}
